package com.dss.auto_deploy.controller;

import com.dss.auto_deploy.vo.AdmProjectVo;
import com.dss.auto_deploy.dto.AdmProjectAddDto;
import com.dss.auto_deploy.dto.AdmProjectPageDto;
import com.dss.auto_deploy.dto.AdmProjectUpdateDto;
import com.dss.auto_deploy.service.IAdmProjectService;
import com.dss.auto_deploy.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
* 开发项目
* @Description:开发项目控制层
* @author dongshoushan
* @date 2022-09-22 14:39:06
*/
@RestController
@RequestMapping("/admProject")
@RequiredArgsConstructor(onConstructor = @_(@Autowired))
@Api(tags ="99: 开发项目")
public class AdmProjectController  {

    /**
    * 开发项目Service
    */
    private final  IAdmProjectService admProjectService;

    /**
    * 新增开发项目
    * @param addDto
    * @return
    */
    @PostMapping
    @ApiOperation(value = "新增开发项目", notes="新增开发项目")
    public Result insert(@RequestBody @Valid AdmProjectAddDto addDto) {
        admProjectService.insert(addDto);
        return Result.success("新增成功");
    }

    /**
    * 修改开发项目
    * @param updateDto
    * @return
    */
    @PutMapping
    @ApiOperation(value = "修改开发项目", notes="修改开发项目")
    public Result update(@RequestBody @Valid AdmProjectUpdateDto updateDto) {
        admProjectService.update(updateDto);
        return Result.success("修改成功");
    }

    /**
    * 批量删除开发项目
    * @param ids
    * @return
    */
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除开发项目", notes="删除开发项目")
    public Result deleteBatch(@PathVariable Long[] ids) {
        admProjectService.deleteBatch(ids);
        return Result.success("删除成功");
    }

    /**
    * 分页查询开发项目
    * @param pageDto
    * @return
    */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询开发项目", notes="分页查询开发项目")
    public  Result page(AdmProjectPageDto pageDto){
        return Result.success(admProjectService.list(pageDto));
    }

    /**
     * 查询开发项目
     * @param
     * @return
     */
    @GetMapping("/getAll")
    @ApiOperation(value = "查询开发项目", notes="查询开发项目")
    public List<AdmProjectVo> getAll(String name){
        return admProjectService.getAll(name);
    }
}
